//
//  ZSPSearchManager.m
//  ZSP_IOS
//
//  Created by Bruce on 2019/10/6.
//  Copyright © 2019 mlqk. All rights reserved.
//

#import "ZSPSearchManager.h"
#import "ZSPSearchResultModel.h"
//#import "ZSPSearchGroupModel.h"
//#import "RCDUtilities.h"

#define SearchLimit  100

@interface ZSPSearchManager ()

/**
 平台好友
 */
@property (nonatomic,strong) NSArray *zspFriendList;
/**
 通讯录好友
 */
@property (nonatomic,strong) NSArray *LocalFriendList;
/**
 平台用户
 */
@property (nonatomic,strong) NSArray *zspUserList;
/**
 我的群组列表
 */
@property (nonatomic,strong) NSArray *groupList;

/**
 平台群组列表
 */
@property (nonatomic,strong) NSArray *zspGroupList;

/**
 会话记录
 */
@property (nonatomic,strong) NSArray *chatList;
@property (nonatomic,assign) NSInteger searchType;
@property (nonatomic,copy) RCDSearchDataManagerBlock result;
@property (nonatomic,copy) NSString *searchText;
@property (nonatomic,copy) NSString *oldSearchText;

@property (nonatomic,assign) UInt64 lastDate;
@property (nonatomic,assign) BOOL isLoad;

@end
@implementation ZSPSearchManager
+ (instancetype)shareInstance {
    static ZSPSearchManager *searchDataManager;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        searchDataManager = [[[self class] alloc] init];
    });
    return searchDataManager;
}
- (void)initData
{
    self.isLoad = NO;
    self.oldSearchText = nil;
}

- (void)searchDataWithSearchText:(NSString *)searchText
                    bySearchType:(NSInteger)searchType
                        complete:(RCDSearchDataManagerBlock)result {
    self.searchText = searchText;
    self.result = result;
    NSString *searchStr = [searchText stringByReplacingOccurrencesOfString:@" " withString:@""];
    if (!searchText.length || searchStr.length == 0) {
        return result(nil, nil);
    }
    self.searchType = searchType;
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    NSMutableArray *array = [NSMutableArray array];
    if (searchType == ZSPSearchFriend || searchType == ZSPSearchAll || searchType == ZSPSearchHome || searchType == ZSPSearchAddressBook) {
        NSArray *friendArray = [self searchFriendBysearchText:searchText];
        self.zspFriendList = friendArray;
        if (friendArray.count > 0) {
            [dic setObject:friendArray forKey:ZSPSearchFriendString];
            [array addObject:ZSPSearchFriendString];
        }
    }
    if ( searchType == ZSPSearchAll || searchType == ZSPSearchUSer || searchType == ZSPSearchHome ) {
//        搜索平台用户
        [self searchLITUsertext:searchText];
        self.zspUserList = @[];
    }
    if ( searchType == ZSPSearchAll|| searchType == ZSPSearchLocal || searchType == ZSPSearchHome || searchType == ZSPSearchAddressBook) {
        NSArray *friendArray = [self searchLocalBysearchText:searchText];
        self.LocalFriendList = friendArray;
        
        if (friendArray.count > 0) {
            [dic setObject:friendArray forKey:ZSPSearchLocalString];
            [array addObject:ZSPSearchLocalString];
        }
    }
    if (searchType == ZSPSearchGroup || searchType == ZSPSearchAll || searchType == ZSPSearchAddressBook) {
        NSArray *groupArray = [self searchGroupBysearchText:searchText];
        self.groupList = groupArray;
        
        if (groupArray.count > 0) {
            [dic setObject:groupArray forKey:ZSPSearchGroupString];
            [array addObject:ZSPSearchGroupString];
        }
    }
    if (searchType == ZSPSearchChatHistory || searchType == ZSPSearchAll || searchType == ZSPSearchHome) {
        NSArray *messsageResult = [self searchMessageBysearchText:searchText];
        self.chatList = messsageResult;
        
        if (messsageResult.count > 0) {
            [dic setObject:messsageResult forKey:ZSPSearchChatHistoryString];
            [array addObject:ZSPSearchChatHistoryString];
        }
    }
    if (searchType == ZSPSearchZSPGroup)
    {
        //搜索平台群组
        [self searchZSPGroup:searchText];
        self.zspGroupList = @[];
    }
    result(dic.copy, array.copy);
}

- (NSArray *)searchFriendBysearchText:(NSString *)searchText {
    NSMutableArray *friendResults = [NSMutableArray array];
    
//    NSArray *friendArray = [[NIMSDK sharedSDK].userManager myFriends];
//    for (NIMUser *user in friendArray) {
//        //        if ([user.status isEqualToString:@"20"]) {
//        if (user.alias && [ZSPTool isContains:user.alias withString:searchText]) {
//            ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//            model.sessionType = NIMSessionTypeP2P;
//            model.targetId = user.userId;
//            model.otherInformation = user.alias;
//            model.portraitUri = user.userInfo.avatarUrl;
//            model.searchType = ZSPSearchFriend;
//            [friendResults addObject:model];
//        } else if ([ZSPTool isContains:user.userInfo.nickName withString:searchText]) {
//            ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//            model.sessionType = NIMSessionTypeP2P;
//            model.targetId = user.userId;
//            model.name = user.userInfo.nickName;
//            model.portraitUri = user.userInfo.avatarUrl;
//            if (user.alias) {
//                model.otherInformation = user.alias;
//            }
//            model.searchType = ZSPSearchFriend;
//            
//            [friendResults addObject:model];
//        }
//        //        }
//    }
    return friendResults;
}
- (NSArray *)searchLocalBysearchText:(NSString *)searchText {
    NSMutableArray *friendResults = [NSMutableArray array];
//    NSArray *localarray = [ZSP_AddressBook_Singleton sharedAddressBook].addressBookList;
//    for (CNContact *contact in localarray) {
//        NSArray *phoneNumbers =contact.phoneNumbers;
//        
//        if ([self checkIsFeiend:phoneNumbers]) {
//            //是我的好友所以不显示
//        }
//        else
//        {
//            NSString *fullName = [CNContactFormatter stringFromContact:contact style:CNContactFormatterStyleFullName];
//            if (fullName && [ZSPTool isContains:fullName withString:searchText]) {
//                
//                LJPerson *person = [[LJPerson alloc] initWithCNContact:contact];
//                ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//                model.sessionType = NIMSessionTypeP2P;
//                model.targetId = contact.identifier;
//                model.otherInformation = fullName;
//                model.portraitUri = @"ss";
//                model.searchType = ZSPSearchLocal;
//                model.person = person;
//                [friendResults addObject:model];
//            }
//            else
//            {
//                
//            }
//        }
//        
//    }
    return friendResults;
}

- (void)searchZSPGroup:(NSString *)searchText
{
    if (self.isLoad)
    {
        DLog(@"加载中");
        
        return;
    }
    if (self.oldSearchText) {
        if ([self.oldSearchText isEqualToString:searchText]) {
            DLog(@"两次请求一样");
            
            return;
        }
    }
    DLog(@"可以请求");
    
    if (self.lastDate)
    {
        
        UInt64 msecond = [[NSDate date] timeIntervalSince1970]*1000;
        UInt64 time =  msecond - self.lastDate;
        DLog(@"%llu",time);
        if(time >= 1200)
        {
            //已经超过一天了，我不管了
            DLog(@"请求%@",searchText);
            
        }
        else
        {
            
            [self performSelector:@selector(searchLITUsertext:) withObject:searchText afterDelay:(1200 - time)/1000.0];
            return;
        }
        
    }
    self.oldSearchText = searchText;
    
    self.isLoad = YES;
    
    NSMutableArray *zspGroupResults = [NSMutableArray array];
    
    
//    [ZSPRequestTool zsp_tGroup_queryByName_WithName:searchText pageNo:@"1" pageSize:@"50" successHandle:^(id  _Nonnull response) {
//        self.lastDate = [[NSDate date] timeIntervalSince1970]*1000;
//
//        self.isLoad = NO;
//
//        NSArray *array1 = response[@"rows"];
//        for (int i= 0; i< array1.count; i++)
//        {
//            NSDictionary *dict = array1[i];
//            ZSPSearchGroupModel *tempmodel = [ZSPSearchGroupModel yy_modelWithDictionary:dict];
//
////            NSDictionary *dict = array1[i];
////            ZSPUserInforModel *userModel = [ZSPUserInforModel yy_modelWithDictionary:dict];
//            ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//            model.sessionType = NIMSessionTypeTeam;
//            model.targetId = NSStringFormat(@"%@",tempmodel.imTid);
//            model.otherInformation = tempmodel.groupName;
//            model.portraitUri = tempmodel.groupImage;
//            model.searchType = ZSPSearchZSPGroup;
//            [zspGroupResults addObject:model];
//        }
        self.zspGroupList = zspGroupResults;
        
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
        NSMutableArray *array = [NSMutableArray array];
        if (self.searchType == ZSPSearchFriend || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
            if (self.zspFriendList.count > 0) {
                [dic setObject:self.zspFriendList forKey:ZSPSearchFriendString];
                [array addObject:ZSPSearchFriendString];
            }
        }
        if ( self.searchType == ZSPSearchUSer ||  self.searchType == ZSPSearchAll ||self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
            
            if (self.zspUserList.count > 0) {
                [dic setObject:self.zspUserList forKey:ZSPSearchUSerString];
                [array addObject:ZSPSearchUSerString];
            }
        }
        if ( self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook||self.searchType == ZSPSearchLocal) {
            
            if (self.LocalFriendList.count > 0) {
                [dic setObject:self.LocalFriendList forKey:ZSPSearchLocalString];
                [array addObject:ZSPSearchLocalString];
            }
        }
        if (self.searchType == ZSPSearchGroup || self.searchType == ZSPSearchAll) {
            
            if (self.groupList.count > 0) {
                [dic setObject:self.groupList forKey:ZSPSearchGroupString];
                [array addObject:ZSPSearchGroupString];
            }
        }
        if (self.searchType == ZSPSearchChatHistory || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome) {
            
            if (self.chatList.count > 0) {
                [dic setObject:self.chatList forKey:ZSPSearchChatHistoryString];
                [array addObject:ZSPSearchChatHistoryString];
            }
        }
        if (self.searchType == ZSPSearchZSPGroup ) {
            
            if (self.zspGroupList.count > 0) {
                [dic setObject:self.zspGroupList forKey:ZSPSearchZSPGroupString];
                [array addObject:ZSPSearchZSPGroupString];
            }
        }
        self.result(dic.copy, array.copy);
//    } failureHandle:^(NSError * _Nonnull error) {
//        self.lastDate = [[NSDate date] timeIntervalSince1970]*1000;
//
//        self.isLoad = NO;
//        DLog(@"请求玩了");
//
//    }];
}

- (void)searchLITUsertext:(NSString *)searchText {
    
    if (self.isLoad)
    {
        DLog(@"加载中");
        
        return;
    }
    if (self.oldSearchText) {
        if ([self.oldSearchText isEqualToString:searchText]) {
            DLog(@"两次请求一样");
            
            return;
        }
    }
    DLog(@"可以请求");
    
    if (self.lastDate)
    {
        
        UInt64 msecond = [[NSDate date] timeIntervalSince1970]*1000;
        UInt64 time =  msecond - self.lastDate;
        DLog(@"%llu",time);
        if(time >= 1200)
        {
            //已经超过一天了，我不管了
            DLog(@"请求%@",searchText);
            
        }
        else
        {
            
            [self performSelector:@selector(searchLITUsertext:) withObject:searchText afterDelay:(1200 - time)/1000.0];
            return;
        }
        
    }
    self.oldSearchText = searchText;
    
    self.isLoad = YES;
    
    NSMutableArray *zspUserResults = [NSMutableArray array];
    
    
//    [ZSPRequestTool zsp_member_searchFriend_RequestWithId:[ZSPTool selfUserId] nickName:searchText pageNo:@"1" pageSize:@"50" successHandle:^(id  _Nonnull response) {
//        self.lastDate = [[NSDate date] timeIntervalSince1970]*1000;
//
//        self.isLoad = NO;
//
//        NSArray *array1 = response[@"rows"];
//            for (int i= 0; i< array1.count; i++)
//            {
//                NSDictionary *dict = array1[i];
//                ZSPUserInforModel *userModel = [ZSPUserInforModel yy_modelWithDictionary:dict];
//                ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//                model.sessionType = NIMSessionTypeP2P;
//                model.targetId = NSStringFormat(@"%ld",userModel.userId);
//                model.otherInformation = userModel.nickName;
//                model.portraitUri = userModel.mrAvatar;
//                model.searchType = ZSPSearchUSer;
//                [zspUserResults addObject:model];
//            }
        self.zspUserList = zspUserResults;
        
            NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
            NSMutableArray *array = [NSMutableArray array];
            if (self.searchType == ZSPSearchFriend || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
                if (self.zspFriendList.count > 0) {
                    [dic setObject:self.zspFriendList forKey:ZSPSearchFriendString];
                    [array addObject:ZSPSearchFriendString];
                }
            }
            if ( self.searchType == ZSPSearchUSer ||  self.searchType == ZSPSearchAll ||self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {

                if (zspUserResults.count > 0) {
                    [dic setObject:zspUserResults forKey:ZSPSearchUSerString];
                    [array addObject:ZSPSearchUSerString];
                }
            }
            if ( self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook||self.searchType == ZSPSearchLocal) {

                if (self.LocalFriendList.count > 0) {
                    [dic setObject:self.LocalFriendList forKey:ZSPSearchLocalString];
                    [array addObject:ZSPSearchLocalString];
                }
            }
            if (self.searchType == ZSPSearchGroup || self.searchType == ZSPSearchAll) {

                if (self.groupList.count > 0) {
                    [dic setObject:self.groupList forKey:ZSPSearchGroupString];
                    [array addObject:ZSPSearchGroupString];
                }
            }
            if (self.searchType == ZSPSearchChatHistory || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome) {

                if (self.chatList.count > 0) {
                    [dic setObject:self.chatList forKey:ZSPSearchChatHistoryString];
                    [array addObject:ZSPSearchChatHistoryString];
                }
            }
            self.result(dic.copy, array.copy);
//    } failureHandle:^(NSError * _Nonnull error) {
//            self.lastDate = [[NSDate date] timeIntervalSince1970]*1000;
//
//            self.isLoad = NO;
//            DLog(@"请求玩了");
//
//            [self checkSearchTextWithOldText:searchText];
//    }];
//    [LITRequest postNo_tWithURL:LIT_URL_UserInfo_Search withParams:params withLoadAnimal:YES successBlock:^(id result) {
//        DLog(@"请求玩了");
//        self.lastDate = [[NSDate date] timeIntervalSince1970]*1000;
//
//        self.isLoad = NO;
//        [self checkSearchTextWithOldText:searchText];
//        NSDictionary *dic = result;
//        int code = [dic[@"code"] intValue];
//        switch (code) {
//            case 200:
//            {
//                NSArray *array1 = dic[@"data"];
//                for (int i= 0; i< array1.count; i++)
//                {
//                    NSDictionary *dict = array1[i];
//                    RCDSearchResultModel *model = [[RCDSearchResultModel alloc] init];
//                    model.conversationType = ConversationType_PRIVATE;
//                    model.targetId = TOSTRING(dict[@"id"]);
//                    model.otherInformation = TOSTRING(dict[@"n"]);
//                    model.portraitUri = TOSTRING(dict[@"h"]);
//                    model.searchType = ZSPSearchFriend;
//                    [friendResults addObject:model];
//                }
//
//                NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
//                NSMutableArray *array = [NSMutableArray array];
//                if (self.searchType == ZSPSearchFriend || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
//                    if (self.zspFriendList.count > 0) {
//                        [dic setObject:self.zspFriendList forKey:@"平台好友"];
//                        [array addObject:@"平台好友"];
//                    }
//                }
//                if ( self.searchType == ZSPSearchUSer ||  self.searchType == ZSPSearchAll || self.searchType == ZSPSearchUSer ||self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
//
//                    if (friendResults.count > 0) {
//                        [dic setObject:friendResults forKey:@"平台用户"];
//                        [array addObject:@"平台用户"];
//                    }
//                }
//                if ( self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
//
//                    if (self.LocalFriendList.count > 0) {
//                        [dic setObject:self.LocalFriendList forKey:@"通讯录联系人"];
//                        [array addObject:@"通讯录联系人"];
//                    }
//                }
//                if (self.searchType == ZSPSearchGroup || self.searchType == ZSPSearchAll) {
//
//                    if (self.groupList.count > 0) {
//                        [dic setObject:self.groupList forKey:@"群组"];
//                        [array addObject:@"群组"];
//                    }
//                }
//                if (self.searchType == ZSPSearchChatHistory || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome) {
//
//                    if (self.chatList.count > 0) {
//                        [dic setObject:self.chatList forKey:@"聊天记录"];
//                        [array addObject:@"聊天记录"];
//                    }
//                }
//                self.result(dic.copy, array.copy);
//
//
//            }
//                break;
//
//            default:
//            {
//
//            }
//                break;
//        }
//
//    } failureBlock:^(id error) {
//        self.lastDate = [[NSDate date] timeIntervalSince1970]*1000;
//
//        self.isLoad = NO;
//        DLog(@"请求玩了");
//
//        [self checkSearchTextWithOldText:searchText];
//
//    }];
}


/**
 检验现在查询的数据和现在的检索关键字是否匹配
 
 @param oldText 老的搜索关键字
 */
- (void)checkSearchTextWithOldText:(NSString *)oldText
{
    if ([oldText isEqualToString:self.searchText]) {
        
    }
    else
    {
        [self searchLITUsertext:self.searchText];
    }
}

- (NSArray *)searchGroupBysearchText:(NSString *)searchText {
    NSMutableArray *groupResults = [NSMutableArray array];

//    NSArray *groupArray = [[NIMSDK sharedSDK].teamManager allMyTeams];
//    for (NIMTeam *group in groupArray) {
//        if ([ZSPTool isContains:group.teamName withString:searchText]) {
//            ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//            model.sessionType = NIMSessionTypeTeam;
//            model.targetId = group.teamId;
//            model.name = group.teamName;
//            model.portraitUri = group.avatarUrl;
//            model.searchType = ZSPSearchGroup;
//
//            [groupResults addObject:model];
//            continue;
//
//        }
//    }
    return groupResults;
}

- (NSArray *)searchMessageBysearchText:(NSString *)searchText {
    if (!searchText.length) {
        return nil;
    }
    NSMutableArray *chatArray = [NSMutableArray array];
    
//    NIMMessageSearchOption *option = [[NIMMessageSearchOption alloc] init];
//    option.searchContent = searchText;
//    option.limit         = SearchLimit;
//    option.order         = NIMMessageSearchOrderAsc;
//    option.allMessageTypes = YES;
//    __weak typeof(self) wself = self;
//    
//    [[NIMSDK sharedSDK].conversationManager searchAllMessages:option result:^(NSError * _Nullable error, NSDictionary<NIMSession *,NSArray<NIMMessage *> *> * _Nullable messages) {
//        NSArray *keyArray = [messages allKeys];
//        NSArray *valueArray = [messages allValues];
//        for (int i = 0; i < keyArray.count; i++) {
//            NIMSession *session = keyArray[i];
//            NSArray *tempArray = valueArray[i];
//            ZSPSearchResultModel *model = [[ZSPSearchResultModel alloc] init];
//            model.sessionType = session.sessionType;
//            model.targetId = session.sessionId;
//            if (tempArray.count > 1) {
//                model.otherInformation = [NSString stringWithFormat:@"%ld条相关的记录", tempArray.count];
//            } else {
//                NIMMessage *message = tempArray[0];
//                NSString *string =   message.text;
//                
//                model.messageType = message.messageType;
//                
//                model.otherInformation = [self relaceEnterBySpace:string];
//            }
//            if (session.sessionType == NIMSessionTypeP2P) {
//                NIMKitInfo *user = [[NIMKit sharedKit] infoByUser:session.sessionId option:nil];
//                model.name = user.showName;
//                model.portraitUri = user.avatarUrlString;
//            } else if (session.sessionType == NIMSessionTypeTeam) {
//                NIMKitInfo *user = [[NIMKit sharedKit] infoByTeam:session.sessionId option:nil];
//                model.name = user.showName;
//                model.portraitUri = user.avatarUrlString;
//            }
//            model.searchType = ZSPSearchChatHistory;
//            model.count = (int)tempArray.count;
//            [chatArray addObject:model];
//            self.chatList = chatArray;
//            NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
//            NSMutableArray *array = [NSMutableArray array];
//            if (self.searchType == ZSPSearchFriend || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
//                if (self.zspFriendList.count > 0) {
//                    [dic setObject:self.zspFriendList forKey:ZSPSearchFriendString];
//                    [array addObject:ZSPSearchFriendString];
//                }
//            }
//            if ( self.searchType == ZSPSearchUSer ||  self.searchType == ZSPSearchAll||self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook) {
//
//                if (self.zspUserList.count > 0) {
//                    [dic setObject:self.zspUserList forKey:ZSPSearchUSerString];
//                    [array addObject:ZSPSearchUSerString];
//                }
//            }
//            if ( self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome || self.searchType == ZSPSearchAddressBook || self.searchType == ZSPSearchLocal) {
//
//                if (self.LocalFriendList.count > 0) {
//                    [dic setObject:self.LocalFriendList forKey:ZSPSearchLocalString];
//                    [array addObject:ZSPSearchLocalString];
//                }
//            }
//            if (self.searchType == ZSPSearchGroup || self.searchType == ZSPSearchAll) {
//
//                if (self.groupList.count > 0) {
//                    [dic setObject:self.groupList forKey:ZSPSearchGroupString];
//                    [array addObject:ZSPSearchGroupString];
//                }
//            }
//            if (self.searchType == ZSPSearchChatHistory || self.searchType == ZSPSearchAll || self.searchType == ZSPSearchHome) {
//
//                if (self.chatList.count > 0) {
//                    [dic setObject:self.chatList forKey:ZSPSearchChatHistoryString];
//                    [array addObject:ZSPSearchChatHistoryString];
//                }
//            }
//            self.result(dic.copy, array.copy);
//        }
//   
//    }];
        
    return chatArray;
}

- (NSString *)relaceEnterBySpace:(NSString *)originalString {
    NSString *string = [originalString stringByReplacingOccurrencesOfString:@"\r\n" withString:@" "];
    string = [string stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
    string = [string stringByReplacingOccurrencesOfString:@"\r" withString:@" "];
    return string;
}



- (NSString *)changeString:(NSString *)str appendStr:(NSString *)appendStr {
    if (str.length > 0) {
        str = [NSString stringWithFormat:@"%@,%@", str, appendStr];
    } else {
        str = appendStr;
    }
    return str;
}

#pragma mark -- 检查判断

/**
 判断是否是自己朋友 根据手机号判断
 
 @param phoneNumbers 手机号s
 @return 是否是朋友
 */
- (BOOL)checkIsFeiend:(NSArray *)phoneNumbers
{
//    NSArray *friendArray = [[RCDataBaseManager shareInstance] getAllFriends];
//    for (CNLabeledValue *labeledValue in phoneNumbers) {
//        CNPhoneNumber *phoneValue = labeledValue.value;
//        NSString *phoneNumber = phoneValue.stringValue;
//        for (RCDUserInfo *userInfo in friendArray) {
//            
//            if ([userInfo.phone isEqualToString:phoneNumber]) {
//                return YES;
//                
//            }
//        }
//    }
    
    return NO;
}

@end
